package be.rubengerits.test;

public class JsonUtils {
	private static final String SPLIT = "_";

	private static final String EMPTY = "";

	private JsonUtils() {
	}

	/*
	 * Convert lowecase string with underscores to name
	 */
	public static String constructName(String name) {
		return constructName(EMPTY, name);
	}

	/*
	 * Convert lowecase string with underscores to name with prefix
	 */
	public static String constructName(String prefix, String name) {
		StringBuilder methodName = new StringBuilder();

		if (name.length() > 0) {
			methodName.append(prefix);

			String[] names = name.split(SPLIT, 2);
			methodName.append(Character.toUpperCase(names[0].charAt(0)));
			methodName.append(names[0].substring(1));

			if (names.length > 1) {
				methodName.append(constructName(names[1]));
			}
		}
		return methodName.toString();
	}
	
	public static String constructFieldName(String name) {
		StringBuilder methodName = new StringBuilder();

		if (name.length() > 0) {
			String[] names = name.split(SPLIT, 2);
			methodName.append(names[0]);

			if (names.length > 1) {
				methodName.append(constructName(names[1]));
			}
		}
		return methodName.toString();
	}
}
